#pragma once
#include <IceUtil\Handle.h>
#include <IceUtil\Shared.h>
#include "XThreadSafeQueue.h"

namespace Xts
{
	namespace Util
	{
		//Interface of Product Class for the Thread Safe Producer-Consumer model
		class IXRequestJob : public ::IceUtil::Shared
		{
		public:
			IXRequestJob(void);
			~IXRequestJob(void);

			virtual bool Execute(void) = 0;
			//"Execute" should be realized in derived class. When "Execute" return false, working thread would end.
			//Any Job, except XEndingReaderJob objcet, should return true.
		};
		typedef ::IceUtil::Handle<IXRequestJob> IXRequestJobPtr;
		typedef XThreadSafeQueue<IXRequestJobPtr> XRequestQueue;
		typedef ::IceUtil::Handle<XRequestQueue> XRequestQueuePtr;

		//XEndingReaderJob is used to end working thread. 
		//When you want to end a Thread Safe Producer-Consumer model's all working Thread, 
		//add the same number XEndingReaderJob objects with working threads to Job queue.

		class XEndingReaderJob : public IXRequestJob
		{
		public:
			XEndingReaderJob(){}
			~XEndingReaderJob(){}

		private:
			virtual bool Execute(void){ return false; }
		};
	}
}


